<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1>2134</h1>
    <xxx>456</xxx>

    <script>
      function Person(name) {
        // 给实例添加私有属性(私有数据),就是在构造函数中利用this添加私有属性
        // this就是Person实例
        this.name = name
      }

      Person.prototype.say = function () {
        console.log('我是', this.name)
      }
      class Person {
        constructor(name) {
          this.name = name
        }
        say() {
          console.log('我是', this.name)
        }
      }

      const zs = new Person('zs')
      console.log(zs)
      const ls = new Person('ls')
      console.log(ls)
      zs.say()
      ls.say()

      function Student(name, score) {
        Person.call(this, name) // 用来继承私有属性
        this.score = score
      }

      // 用来继承Person原型的方法的
      Student.prototype = new Person()

      // class Student extends Person {
      //   constructor(name, score) {
      //     super(name)
      //     // 使用类给实例添加私有属性(私有数据),也是通过this找到实例对象,然后给实例添加私有属性
      //     this.score = score
      //   }
      // }

      const s1 = new Student('zs', 100)
      console.log(s1)
      s1.say()
      // const s2 = new Student(99)
      // console.log(s2)
    </script>
  </body>
</html>
